{% extends 'dashboard/base.html' %}

{% block body %}
<script type="text/javascript">
    const $ = jQuery;
    $("#checkAll").change(function () {
        $("input:checkbox").prop('checked', $(this).prop("checked"));
    });
    $(document).ready(function() {
        $('.btn-danger').click(function(){
            if (confirm('Are you sure you want to delete this?')) {
                var scan_id = ['a7af5b68-b661-45ad-90fd-ffa27526cdce'];
                $.each($("input[name='del_scan_id']:checked"), function(){
                    scan_id.push($(this).val());
                });

                var json_scanid = scan_id.join(", ");
                $.ajax({
                    type:'POST',
                    <!--contentType: 'application/json; charset=utf-8',-->
                    url:'{% url 'zapscanner:del_zap_scan' %}',
                    data:{
                       scan_id: json_scanid,
                       csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val()
                    },
                    sucess:function(){

                    }
                });
                setTimeout(function(){location.reload();},1000);
            }
        });

    });

    $(document).ready(function() {
        $('.btn-primary').click(function(){
                var scan_id = ['a7af5b68-b661-45ad-90fd-ffa27526cdce'];
                $.each($("input[name='del_scan_id']:checked"), function(){
                    scan_id.push($(this).val());
                });

            document.getElementById("toexport").value = scan_id.join(", ");


        });

    });


$(document).on('click', '.confirm-delete', function(){
    return confirm('Are you sure you want to delete this?');
})




</script>

        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-body">
                        <div class="float-right">
                            <div class="btn-group" role="group" aria-label="Basic example">
                                <a href="{% url 'webscanners:xml_upload' %}" class="btn btn-primary btn-mini"><i
                                        class="icon-upload-alt"></i> Upload XML</a>
                            </div>
                            <button type="button" class="btn btn-danger btn-mini">Delete Selected</button>
                        </div>
                        <br>
                        <br>
                        <div class="float-right">
                            <form action="{% url 'zapscanner:export' %}" method="post"
                                  class="forms-sample">
                                {% csrf_token %}
                                <div class="form-row align-items-center">
                                    <div class="col-auto my-1">
                                        <select name="type" class="custom-select mr-sm-2" id="inlineFormCustomSelect">
                                            <option value="csv" selected>CSV</option>
                                            <option value="json">JSON</option>
                                            <option value="yaml">YAML</option>
                                        </select>
                                    </div>
                                    <div class="col-auto my-1">
                                        <input type="hidden" id="toexport" name="scan_id"/>
                                        <button type="submit" class="btn btn-primary"><i
                                                class="fas fa-arrow-alt-circle-down"></i></button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <br>
                        <div class="d-md-flex align-items-center">
                            <h1 class="card-title"> ZAP Scanner Scan List </h1>
                        </div>
                        <br>
                        <div class="row">
                            <div class="table-responsive">
                                <!--<table id="data_table" class="table table-striped table-bordered" width="100%">-->
                                <table id="data_table" class="table table-bordered data-table">
                                    <thead>
                                    <tr>
                                        <!--<th><p><label><input type="checkbox" id="checkAll"/></label></p></th>-->
                                        <th><label class="customcheckbox m-b-20">
                                            <input type="checkbox" id="mainCheckbox">
                                            <span class="checkmark"></span>
                                        </label></th>
                                        <th>URL</th>
                                        <th>Status</th>
                                        <!--<th>Date Time</th>-->
                                        <th>Total Vulnerability</th>
                                        <th>High</th>
                                        <th>Medium</th>
                                        <th>Low</th>
                                        <th>Info</th>
                                        <th>Duplicates</th>
{#                                        <th></th>#}
{#                                        <th></th>#}
                                    </tr>
                                    </thead>
                                    <tbody>{% for data in all_scans %}
                                    <tr data-target="#">
                                        <td>
                                            <form>
                                                <label class="customcheckbox">
                                                    <input type="checkbox" class="listCheckbox"
                                                           value="{{data.scan_id}}"
                                                           name="del_scan_id"
                                                           onClick="reload">
                                                    <span class="checkmark"></span>
                                                </label>
                                            </form>
                                        </td>
                                        <td>
                                            <a href="{% url 'zapscanner:zap_list_vuln' %}?scan_id={{data.scan_id}}">{{data.scan_url}}</a>
                                        </td>
                                        <td width="20%">
                                            <div>
                                                <div class="d-flex no-block align-items-center">
                                                    <span>{{data.scan_status}}{{data.vul_status}}% Completed</span>
                                                </div>
                                                <div class="progress{% if data.scan_status != '100.0' %} active progress-striped{% endif %}">
                                                    <div class="progress-bar progress-bar-striped" role="progressbar"
                                                         style="width: {{data.scan_status}}{{data.vul_status}}%" aria-valuenow="10" aria-valuemin="0"
                                                         aria-valuemax="100"></div>
                                                </div>
                                            </div>
                                        </td>
                                        <!--<td>{{data.date_time}}</td>-->
                                        <td><span class="badge badge-pill badge-dark">{{data.total_vul}}</span></td>
                                        <td><span class="badge badge-pill badge-danger">{{data.high_vul}}</span></td>
                                        <td><span class="badge badge-pill badge-warning">{{data.medium_vul}}</span></td>
                                        <td><span class="badge badge-pill badge-info">{{data.low_vul}}</span></td>
                                        <td><span class="badge badge-pill badge-info">{{data.info_vul}}</span></td>

                                        <td><span class="badge badge-pill badge-secondary">{{data.total_dup}}</span>
                                        </td>
{#                                        <td>#}
{#                                            <form action="{% url 'zapscanner:zap_scan_pdf_gen' %}" method="post"#}
{#                                                  class="forms-sample">#}
{##}
{#                                                {% csrf_token %}#}
{#                                                <input type="hidden" name="scan_id" value="{{data.scan_id}}"/>#}
{#                                                <input type="hidden" name="scan_url" value="{{data.scan_url}}"/>#}
{##}
{#                                                <button class="btn btn-success btn-sm"><i class="fas fa-file-pdf"></i>#}
{#                                                </button>#}
{#                                            </form>#}
{#                                        </td>#}
{#                                        <td class="confirm-delete">#}
{#                                            <form action="{% url 'zapscanner:del_zap_scan' %}" method="post"#}
{#                                                  class="forms-sample">#}
{##}
{#                                                {% csrf_token %}#}
{#                                                <input type="hidden" name="scan_id"#}
{#                                                       value="{{data.scan_id}}"/>#}
{#                                                <input type="hidden" name="scan_url" value="{{data.scan_url}}"/>#}
{#                                                <button class="btn btn-danger btn-sm"><i class="fas fa-times"></i>#}
{#                                                </button>#}
{#                                            </form>#}
{#                                        </td>#}

                                        {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
{% endblock %}
